package com.itheima;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;

@WebServlet("/xiazai3")
public class xiazai3 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String realPath = this.getServletContext()
                .getRealPath("download/Ace/jpg");
        FileInputStream fis = new FileInputStream(realPath);

        response.setHeader("Content-Disposition","attachment;filename="+"aaa.jpg");

        ServletOutputStream out = response.getOutputStream();
        int len;
        byte[] buffer = new byte[1024*8];
        while((len=fis.read(buffer))!=-1){
            out.write(buffer,0,len);

        }
    }
}
